<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>对手信息</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">
    <script src="../../res/js/jquery-3.1.1.min.js"></script>
    <script src="../../res/layui/layui.js" charset="utf-8"></script>


</head>
<body>

 <!--对手-->
<table class="layui-hide" id="test" lay-filter="test"></table>
<!--对手成绩-->
<table class="layui-hide" id="testt" lay-filter="testt"></table>

<script type="text/html" id="toolbarDemo">
  <div id="kool">
      <div class="layui-inline">
          <input class="layui-input" name="rivName" id="rivName" autocomplete="off" placeholder="请输入要查看的用户">
      </div>
      <input type="button" lay-event="Ser" value="查询" class="layui-btn" id="seachTable">

      <button class="layui-btn" lay-event="add">新增数据</button>
  </div>
</script>

 <!--对手成绩-->
<script type="text/html" id="toolbarDemot">
    <div id="koolt">
        <div class="layui-inline">
            <input class="layui-input" name="matchName" id="matchName" autocomplete="off" placeholder="请输入要查看的比赛">
        </div>
        <input type="button" lay-event="select" value="查询" class="layui-btn" id="seachTablet">

        <button class="layui-btn" lay-event="addt">新增数据</button>
    </div>
</script>

 <!--对手-->
 <script type="text/html" id="barDemo">
     {{# if(d.isva!=0){ }}
     <a class="layui-btn layui-btn-xs" lay-event="edit" >编辑</a>
     <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" >删除</a>
     <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail" >查看</a>
     {{# } else{}}
     <a class="layui-btn layui-btn-disabled layui-btn-xs" lay-event="edit" >编辑</a>
     <a class="layui-btn layui-btn-disabled layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
     <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看对手信息</a>
     {{# } }}
 </script>

<script type="text/html" id="barDemot">
    {{# if(d.isva!=0){ }}
    <a class="layui-btn layui-btn-xs" lay-event="edit" >编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" >删除</a>
    {{# } else{}}
    <a class="layui-btn layui-btn-disabled layui-btn-xs" lay-event="edit" >编辑</a>
    <a class="layui-btn layui-btn-disabled layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    {{# } }}
</script>

<script>
//全局同步
$.ajaxSetup({
	async:false
});

var table2 = "";
layui.use('table', function(){
  var table = layui.table
  ,form = layui.form;
  table2=table.render({
    elem: '#test'
    ,url:'../../AtsRival/findAll'
    ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
    ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
      title: '提示'
      ,layEvent: 'LAYTABLE_TIPS'
      ,icon: 'layui-icon-tips'
    }]
    ,title: '对手信息表'
    ,cols: [[
      //{field:'rivId', title:'ID', width:80, fixed: 'left', unresize: true, sort: true}
      {field:'rivName', title:'对手名字', width:120,fixed: 'left', unresize: true, sort: true}
      ,{field:'rivSex', title:'性别', width:120}
      ,{field:'rivFailing', title:'缺点', width:150}
      ,{field:'rivTechnique', title:'技术风格', width:100}
      ,{field:'rivTactics', title:'战术风格', width:120}
      // ,{field:'sort', title:'排序', width:100}
      ,{field:'creater', title:'创建人', width:100}
      ,{field:'creatTime', title:'创建时间', width:120,templet: "<div>{{layui.util.toDateString(d.creatTime, 'yyyy-MM-dd HH:mm:ss')}}</div>"}
      ,{field:'isva', title:'是否有效', width:100,  templet: '#isva'}
      // ,{field:'remark', title:'备注', width:100}
      ,{field:'rivIdea', title:'应对方案', width:100,}
      ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:190}
    ]]
    ,page: true
      ,limit:5
      ,limits:[5,10]
      // ,done: function (res, curr, count) {
      //     $('tr').css({'background-color': '#009688', 'color': '#fff'});
      // }
  });


    //是否选中事件
    form.on('switch(sexDemo)', function(obj){

        var look=0;
        //layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);
        if(obj.elem.checked==true){
            look=1;
        }else{
            look=0;
        }

        var data={id:this.value,isva:look};
        layer.confirm('确定要修改状态?', function(index){

        var url="../../AtsRival/UpdateState";

        $.post(url,data,function(obj){
            if(obj.num==1){
                layer.msg('操作成功');
                table2.reload();
            }
        });


        });

        table2.reload();

    });


  //头工具栏事件
  table.on('toolbar(test)', function(obj){

    var checkStatus = table.checkStatus(obj.config.id);

    switch(obj.event){

        case 'Ser':
                table2.reload({
                    where: {
                        rivName: $("#rivName").val()
                    },
                    page: { curr: 1 }
                });
            break;
      case 'add'://新增数据
            var data = checkStatus.data;
            layer.open({
                type: 2,
                title: '数据',
                closeBtn: 1, //不显示关闭按钮
                shade: [0],
                area: ['80%', '90%'],
                anim: 2,
                content: ['AtsRivaPanel.html', 'no'], //iframe的url，no代表不显示滚动条
                end: function(){
                    table2.reload();
                }
            });
            break;


      //自定义头工具栏右侧图标 - 提示
      case 'LAYTABLE_TIPS':
        layer.alert('这是工具栏右侧自定义的一个图标按钮');
      break;
    };
  });

  //监听行工具事件
  table.on('tool(test)', function(obj){
    var data = obj.data;
    //解析为json字符串保存子页面接收
      JonData =  JSON.stringify(data);
    if(obj.event === 'del'){
      if(data.isva == 1){
    	var data={rivId:data.rivId,isva:0};
    	layer.confirm('真的删除行么', function(index){
    	var url="../../AtsRival/delete";
  	   	$.post(url,data,function(obj){

	  	   		if(obj.num==1){

	  	   		  layer.msg("操作成功");
	  	   		}
	  	 	 	table2.reload();
  	   		})
    	});
  	  }
      }else if(obj.event === 'edit'){
    	  if(data.isva==1){
    	  layer.open({
			  type: 2,
			  title: '界面编辑',
			  shadeClose: true,
			  shade: 0.8,
			  area: ['580px', '90%'],
			  content: 'AtsRivaPanel.html?id='+data.rivId, //iframe的url
			  end:function(){
				  table2.reload();
			  }
			});
    	  }
   		}else if(obj.event === 'detail'){

        table3.reload({
            url:"../../AtsRival/resultId",
            where: {
                id: data.rivId
            },

            page: { curr: 1 }
        });
    }

 	 });

});
</script>


 <script type="text/html" id="isva">
     {{# if(d.isva!=0) { }}
     <input type="checkbox" value="{{d.rivId}}" name="isva" lay-skin="switch" lay-filter="sexDemo" lay-text="是|否" {{ d.isva == 1 ? 'checked' : '' }}>

     {{# } else{}}
     <input type="checkbox" value="{{d.rivId}}" disabled="" name="isva" lay-skin="switch" lay-filter="sexDemo" lay-text="是|否" {{ d.isva == 1 ? 'checked' : '' }}>

     {{# } }}
 </script>

<script type="text/html" id="isvat">
    {{# if(d.isva!=0) { }}
    <input type="checkbox" value="{{d.resultId}}" name="isva" lay-skin="switch" lay-filter="sexDemot" lay-text="是|否" {{ d.isva == 1 ? 'checked' : '' }}>

    {{# } else{}}
    <input type="checkbox" value="{{d.resultId}}" disabled="" name="isva" lay-skin="switch" lay-filter="sexDemot" lay-text="是|否" {{ d.isva == 1 ? 'checked' : '' }}>

    {{# } }}
</script>



<script>
    var table3 = "";
    var JonData=null;
    layui.use('table', function(){
        var table = layui.table
            ,form = layui.form;
        table3=table.render({
            elem: '#testt'
            ,url:'../../AtsRivalResult/findAll'
            ,toolbar: '#toolbarDemot' //开启头部工具栏，并为其绑定左侧模板
            ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                ,layEvent: 'LAYTABLE_TIPS'
                ,icon: 'layui-icon-tips'
            }]
            ,title: '对手成绩表'
            ,cols: [[
                {field:'resultId', title:'ID', width:80, fixed: 'left', unresize: true, sort: true}
                ,{field:'matchName', title:'比赛名称', width:120}
                ,{field:'matchTime', title:'比赛时间', width:120,templet: "<div>{{layui.util.toDateString(d.matchTime, 'yyyy-MM-dd HH:mm:ss')}}</div>"}
                ,{field:'matchAddr', title:'比赛地点', width:150}
                ,{field:'matchItem', title:'比赛项目', width:100}
                ,{field:'matchResult', title:'比赛成绩', width:120}
                ,{field:'matchSort', title:'比赛排名', width:100}
                // ,{field:'score', title:'积分', width:100}
                ,{field:'rivName', title:'对手姓名', width:100,}
                // ,{field:'sort', title:'排序', width:100}
                ,{field:'creater', title:'创建人', width:100}
                ,{field:'creatTime', title:'创建时间', width:100,templet: "<div>{{layui.util.toDateString(d.creatTime, 'yyyy-MM-dd HH:mm:ss')}}</div>"}
                ,{field:'isva', title:'是否有效', width:100,  templet: '#isvat'}
                ,{field:'remark', title:'备注', width:100,}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemot', width:190}
            ]]
            ,page: true
            ,limit:5
            ,limits:[5,10]

        });

        //修改状态
        form.on('switch(sexDemot)', function(obj){

            var look=0;
            //layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);
            if(obj.elem.checked==true){
                look=1;
            }else{
                look=0;
            }

            var data={id:this.value,isva:look};
            layer.confirm('确定要修改状态?', function(index){

                var url="../../AtsRivalResult/UpdateState";

                $.post(url,data,function(obj){
                    if(obj.num==1){
                        layer.msg('操作成功');

                        table3.reload();
                    }
                });

                table3.reload();
            });



        });

        //头工具栏事件
        table.on('toolbar(testt)', function(obj){

            var checkStatus = table.checkStatus(obj.config.id);

            switch(obj.event){

                case 'select':
                    table3.reload({
                        where: {
                            matchName: $("#matchName").val()
                        },
                        page: { curr: 1 }
                    });
                    break;
                case 'addt'://新增数据

                    var data = checkStatus.data;

                    layer.open({
                        type: 2,
                        title: '数据',
                        closeBtn: 1, //不显示关闭按钮
                        shade: [0],
                        area: ['80%', '90%'],
                        anim: 2,
                        content: 'AtsRivaResultPanel.html',
                        end: function(){
                            table3.reload();
                        }
                    });
                    break;

                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            };
        });

         //监听行工具事件
        table.on('tool(testt)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                if(data.isva == 1){
                    var data={resultId:data.resultId,isva:0};
                    layer.confirm('真的删除行么', function(index){
                        var url="../../AtsRivalResult/delete";
                        $.post(url,data,function(obj){
                            if(obj.num==1){

                                layer.msg("操作成功");
                            }
                            table3.reload();
                        })
                    });
                }
            }else if(obj.event === 'edit'){

                if(data.isva==1){
                    layer.open({
                        type: 2,
                        title: '界面编辑',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['580px', '90%'],
                        content: 'AtsRivaResultPanel.html?resultId='+data.resultId, //iframe的url
                        end:function(){
                            table3.reload();
                        }
                    });
                }
            }
        });



    });


</script>



</body>

</html>